package com.fy.pojo.dto.activity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ActivityDTO {

    /**
     * 活动标题
     */
    private String title;

    /**
     * 活动类型
     * discount-限时特惠
     * newcomer-新人礼包
     * vip-会员专享
     * checkin-签到奖励
     */
    private String type;

    /**
     * 活动开始时间
     */
    private Timestamp startTime;

    /**
     * 活动结束时间
     */
    private Timestamp endTime;

    /**
     * 空间奖励(GB)
     */
    private Integer spaceReward;

    /**
     * 积分奖励
     */
    private Integer pointsReward;

    /**
     * 活动描述
     */
    private String description;

    /**
     * 活动规则
     */
    private String rules;

    /**
     * 活动封面图片URL
     */
    private String cover;

    /**
     * 活动状态
     * 0-未开始
     * 1-进行中
     * 2-已结束
     */
    private Integer status;

    public void setStartTime(String startTime) {
        if (startTime != null && !startTime.isEmpty()) {
            try {
                this.startTime = new Timestamp(Long.parseLong(startTime));
            } catch (NumberFormatException e) {
                try {
                    this.startTime = Timestamp.valueOf(startTime);
                } catch (IllegalArgumentException ex) {
                    throw new IllegalArgumentException("Invalid startTime format: " + startTime);
                }
            }
        }
    }

    public void setEndTime(String endTime) {
        if (endTime != null && !endTime.isEmpty()) {
            try {
                this.endTime = new Timestamp(Long.parseLong(endTime));
            } catch (NumberFormatException e) {
                try {
                    this.endTime = Timestamp.valueOf(endTime);
                } catch (IllegalArgumentException ex) {
                    throw new IllegalArgumentException("Invalid endTime format: " + endTime);
                }
            }
        }
    }
}